package com.rp.api.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ 配置类
 */
@Configuration
public class RabbitMQDelayConfig {


    /**
     * 定义交换机的名字
     */
    public static final String EXCHANGER_DELAY = "exchanger_delay";


    /**
     * 定义队列的名字
     */
    public static final String QUEUE_DELAY = "queue_delay";

    //创建交换机
    @Bean
    public Exchange delayExchange(){

        return ExchangeBuilder
                .topicExchange(EXCHANGER_DELAY)
                .delayed() //开启支持延迟消息
                .durable(true).build();
    }

    //创建队列
    @Bean
    public Queue delayQueue(){

        return new Queue(QUEUE_DELAY);
    }



    //给队列绑定交换机
    public Binding articlehtmlBinding(){
        return BindingBuilder
                .bind(delayQueue())
                .to(delayExchange())
                .with("delay.#")
                .noargs();
    }


}
